//
//  WalletViewController.m
//  jingjing2.0
//
//  Created by apple on 16/5/15.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "WalletViewController.h"
#import "ChargeViewController.h"
#import "MyCouponViewController.h"
#import "MyRewardViewController.h"


@interface WalletViewController ()
@property (nonatomic,strong)UIView * moneyView;
@property (nonatomic,strong)UILabel * leftMoneyLabel;
@property (nonatomic,strong)UIView  * couponView;
@property (nonatomic,strong)UIView  * prizeView;
@end

@implementation WalletViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = GRAYCOLOR;
    self.title = @"净净钱包";
    [self.view addSubview:self.moneyView];
    [self createButtons];
    [self.view addSubview:self.couponView];
    [self.view addSubview:self.prizeView];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [GeneralTool hideTabBar];
    
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [GeneralTool showTabBar];
}
-(UIView *)moneyView
{
    if (!_moneyView)
    {
        _moneyView = [[UIView alloc]initWithFrame:CGRectMake(0, 10+64, kWidth, 60)];
        _moneyView.backgroundColor = [UIColor whiteColor];
        
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapTheMoneyView)];
        [_moneyView addGestureRecognizer:tap];
        
        
        CGFloat width = [@"当前账户可用余额：" sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]}].width;
        UILabel * leftTiplabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, width, 60)];
        leftTiplabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
        leftTiplabel.font = [UIFont systemFontOfSize:16];
        leftTiplabel.text = @"当前账户可用余额：";
        [_moneyView addSubview:leftTiplabel];
        
        _leftMoneyLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(leftTiplabel.frame), 0, 120, 60)];
        _leftMoneyLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
        _leftMoneyLabel.textColor = BLUECOLOR;
        _leftMoneyLabel.text = [NSString stringWithFormat:@"%@元",_money];
        [_moneyView addSubview:_leftMoneyLabel];
        
    }
    return _moneyView;
}
-(void)createButtons
{
    UIButton * chargeBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_moneyView.frame)+1, kWidth/2.0-0.5, 44)];
    chargeBtn.backgroundColor = [UIColor whiteColor];
    [chargeBtn setTitle:@"充值" forState:UIControlStateNormal];
    chargeBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [chargeBtn setImage:[UIImage imageNamed:@"payment_icon"] forState:UIControlStateNormal];
    [chargeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    chargeBtn.autoresizingMask = UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin;
    [chargeBtn addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
    chargeBtn.tag = 111;
    [self.view addSubview:chargeBtn];
    
    UIButton * billBtn = [[UIButton alloc]initWithFrame:CGRectMake(kWidth/2.0+0.5, CGRectGetMaxY(_moneyView.frame)+1, kWidth/2.0-0.5, 44)];
    billBtn.backgroundColor = [UIColor whiteColor];
    [billBtn setTitle:@"账单" forState:UIControlStateNormal];
    [billBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    billBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [billBtn setImage:[UIImage imageNamed:@"bill_icon"] forState:UIControlStateNormal];
    billBtn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleBottomMargin;
    billBtn.tag = 222;
    [billBtn addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:billBtn];
}
-(UIView *)couponView
{
    if (!_couponView)
    {
        _couponView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_moneyView.frame)+45+10, kWidth, 44)];
        _couponView.backgroundColor = [UIColor whiteColor];
        _couponView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapTheCouponView)];
        [_couponView addGestureRecognizer:tap];
        
        UIImageView * couponImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 11, 22, 22)];
        couponImageView.image = [UIImage imageNamed:@"coupon_icon_new"];
        couponImageView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
        [_couponView addSubview:couponImageView];
        
        UILabel * couponLabel = [[UILabel alloc]initWithFrame:CGRectMake(42, 0, 100, 44)];
        couponLabel.text = @"优惠券";
        couponLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
        couponLabel.font = [UIFont systemFontOfSize:16];
        [_couponView addSubview:couponLabel];
        
        UIImageView * access = [[UIImageView alloc]initWithFrame:CGRectMake(kWidth - 22.5, 22-45/4.0, 12.5, 45/2.0)];
        access.image = [UIImage imageNamed:@"right_gray_action"];
        [_couponView addSubview:access];
    }
    return _couponView;
}
-(UIView *)prizeView
{
    if (!_prizeView)
    {
        _prizeView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_couponView.frame)+1, kWidth, 44)];
        _prizeView.backgroundColor = [UIColor whiteColor];
        _prizeView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapThePrizeView)];
        [_prizeView addGestureRecognizer:tap];
        
        UIImageView * couponImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 11, 22, 22)];
        couponImageView.image = [UIImage imageNamed:@"prize_icon"];
        couponImageView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
        [_prizeView addSubview:couponImageView];
        
        UILabel * couponLabel = [[UILabel alloc]initWithFrame:CGRectMake(42, 0, 100, 44)];
        couponLabel.text = @"奖励";
        couponLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
        couponLabel.font = [UIFont systemFontOfSize:16];
        [_prizeView addSubview:couponLabel];
        
        UIImageView * access = [[UIImageView alloc]initWithFrame:CGRectMake(kWidth - 22.5, 22-45/4.0, 12.5, 45/2.0)];
        access.image = [UIImage imageNamed:@"right_gray_action"];
        [_prizeView addSubview:access];
    }
    return _prizeView;
}
-(void)buttonTapped:(UIButton *)sender
{
    if (sender.tag == 111)
    {
        //充值
        ChargeViewController * chargeVc = [[ChargeViewController alloc]init];
        [self.navigationController pushViewController:chargeVc animated:YES];
        
    }else
    {
        //账单
    }
}
-(void)tapThePrizeView
{
//    奖励
    MyRewardViewController * myRewardVc = [[MyRewardViewController alloc]init];
    [self.navigationController pushViewController:myRewardVc animated:YES];
}
-(void)tapTheCouponView
{
//    优惠卷
    MyCouponViewController * couponVc = [[MyCouponViewController alloc]init];
    [self.navigationController pushViewController:couponVc animated:YES];
}
-(void)tapTheMoneyView
{
//    账户余额
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
